package com.jp.knowledge.my.business;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.text.TextUtils;

import com.jp.knowledge.my.model.ContactsModel;
import com.jp.knowledge.my.util.PinyinComparator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gzejia 978862664@qq.com
 */
public class ContactsBusiness {

    public List<ContactsModel> getContactCompany() {
        String[] name = {"安亚敏", "白雯倩", "白中期", "蔡鑫怡", "曹明", "陈安", "陈崇恭", "戴安娜", "道明寺"};
        String[] imgUrl = {
                "http://img2.imgtn.bdimg.com/it/u=65693088,620645654&fm=21&gp=0.jpg",
                "http://img4.imgtn.bdimg.com/it/u=3556354988,1632408036&fm=21&gp=0.jpg",
                "http://img4.imgtn.bdimg.com/it/u=1425972139,1057908849&fm=21&gp=0.jpg",
                "http://img5.imgtn.bdimg.com/it/u=3513715794,3905546937&fm=21&gp=0.jpg",
                "http://img2.imgtn.bdimg.com/it/u=1337071823,298452525&fm=21&gp=0.jpg",
                "http://img4.imgtn.bdimg.com/it/u=138599861,345053951&fm=21&gp=0.jpg",
                "http://img2.imgtn.bdimg.com/it/u=165474088,203424886&fm=21&gp=0.jpg",
                "http://img4.imgtn.bdimg.com/it/u=1425972139,1057908849&fm=21&gp=0.jpg",
                "http://img5.imgtn.bdimg.com/it/u=3513715794,3905546937&fm=21&gp=0.jpg"};
        String[] branch = {"销售专员-广州销售部", "市场活动中间-广州分公司", "大客户部中间-广州销售部",
                "核算-财务中心", "海外事业部总监-上海服务部", "市场活动中间-广州分公司",
                "服务专员-广州服务部", "市场活动中间-广州分公司", "大客户部中间-广州销售部"};
        String[] remark = {"A", "B", "B", "C", "C", "C", "C", "D", "D"};
        String[] phone = {"13650702290", "15812254487", "13788565412", "19754844456", "13845455255",
                "15014223366", "13412555446", "15812254487", "13788565412"};
        String[] stats = {"0", "1", "0", "0", "1", "0", "0", "0", "0"};
        List<ContactsModel> models = new ArrayList<>();

        for (int i = 0, k = name.length; i < k; i++) {
            ContactsModel model = new ContactsModel();
            model.setName(name[i]);
            model.setUrl(imgUrl[i]);
            model.setBranch(branch[i]);
            model.setRemark(remark[i]);
            model.setPhone(phone[i]);
            model.setStats(stats[i]);
            models.add(model);
        }
        return models;
    }

    public List<ContactsModel> getContactPhone(Context context) {
        List<ContactsModel> models = new ArrayList<>();
        Cursor cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);

        while (cursor.moveToNext()) {
            ContactsModel model = new ContactsModel();
            model.setName(cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME)));
            model.setPhone(cursor.getString(cursor.getColumnIndex(Phone.NUMBER)));

            if (!TextUtils.isEmpty(model.getName())) {
                model.setRemark(String.valueOf(PinyinComparator.getPinyin(
                        String.valueOf(model.getName().charAt(0))).charAt(0)));
            } else {
                model.setRemark("#");
            }

            models.add(model);
        }
        return models;
    }
}
